/**
 *
 */
package it.unical.canonaco.rende.igpe.game.cbv.guilayer.match.components;
 
import it.unical.canonaco.rende.igpe.game.cbv.guilayer.components.OverallGUILayoutFactory;
import it.unical.canonaco.rende.igpe.game.cbv.guilayer.guievents.CharacterClickEvent;
import it.unical.canonaco.rende.igpe.game.cbv.guilayer.guievents.GraphicEvent;
import it.unical.canonaco.rende.igpe.game.cbv.guilayer.guievents.GraphicEventListener;
import it.unical.canonaco.rende.igpe.game.cbv.guilayer.guievents.GraphicEventManager;
import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.SettingsBean;
import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.actions.ActionCoordinateInfo;
import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.actions.ActionMediator;
import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.actions.EndTurnAction;
import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.actions.MovementAction;
 

import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events.AttackEvent;
import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events.EventListener;
import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events.EventManager;
import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events.GenericEvent;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;
 










import javax.swing.JButton;
import javax.swing.JPanel;
 
/**
 * @author Massimo Canonaco
 *
 */
class BaseInformationPanel016 extends JPanel implements GraphicEventListener
{

	static public final String NAME = "BasePanel";
	
	private JButton attackButton;
	private JButton moveButton;
	
	BaseInformationPanel016(final CharacterStatusPanel016 container, Map<String,String> settings)
	{
		super();
		GraphicEventManager gem = GraphicEventManager.getInstance();
		gem.addListener(this, CharacterClickEvent.class);
		OverallGUILayoutFactory gui = OverallGUILayoutFactory.getInstance();
		float textSize = Float.parseFloat(settings.get("characterinformationpanel.button.text.size"));
		Dimension buttonSize = new Dimension(Integer.parseInt(settings.get("characterinformationpanel.button.width")), Integer.parseInt(settings.get("characterinformationpanel.button.height")));
//		JButton endTurn = new JButton("Fine turno");
		JButton endTurn = gui.createButtonUniState(textSize, "Fine Turno", buttonSize.width, buttonSize.height,OverallGUILayoutFactory.BUTTON_STATE_ACTIVE);
		endTurn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) 
			{
//				container.getCicp().getMatchManagerMonitor().getClientPlayer().getActions().setAction(NextTurnAction.GUID);
				container.getCicp().getMatchManagerMonitor().getClientPlayer().getActions().setAction(EndTurnAction.GUID);

			}
		});
		
//		moveButton = new JButton("Muovi");
		moveButton = gui.createButtonUniState(textSize, "Muovi", buttonSize.width, buttonSize.height,OverallGUILayoutFactory.BUTTON_STATE_ACTIVE);
//		moveButton.setSize(150, 150);
		moveButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) 
			{
				container.getCicp().setReady(true);
				ActionMediator mediator = container.getCicp().getMatchManagerMonitor().getClientPlayer().getActions();
				mediator.clearInformations();
				mediator.setAction(MovementAction.GUID);
//				System.out.println("aaaa container.getCicp().getActualCharacter()"+container.getCicp().getActualCharacter().getName().+" ");
				mediator.getCurrentAction().reset();
				mediator.addActionInfo(new ActionCoordinateInfo(container.getCicp().getActualCharacter().getRow(), container.getCicp().getActualCharacter().getColumn()));
//				container.getCicp().getMatchManagerMonitor().getCurrentPlayer().getActions().setAction(MovementAction.GUID);
			}
		});
		
//		attackButton = new JButton("Attack");
		attackButton = gui.createButtonUniState(textSize, "Attacca", buttonSize.width, buttonSize.height,OverallGUILayoutFactory.BUTTON_STATE_ACTIVE);
//		attackButton.setSize(150, 150);
		attackButton.addActionListener(new ActionListener() 
		{
			
			@Override
			public void actionPerformed(ActionEvent e) 
			{
				container.showAttackPanel();
			}
		});
		
		add(moveButton);
		add(attackButton);
		add(endTurn);
		setOpaque(false);
	}

	public void disableComponents() 
	{
		moveButton.setEnabled(false);
		attackButton.setEnabled(false);
	}

	public void enableComponents() {
		moveButton.setEnabled(true);
		attackButton.setEnabled(true);
	}

	@Override
	public void notify(GraphicEvent event) {

         if (event.getClass() == CharacterClickEvent.class) {
        	 CharacterClickEvent sce = (CharacterClickEvent) event;
        	 if(!sce.getClickedChar().isSpellCastable())
        		 attackButton.setEnabled(false);
        	 else attackButton.setEnabled(true);
        	 
         }
	}
	
}


